import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex)
export default {
    state: {
        //菜单栏数据
        menuList: [],
        //权限数据
        permList: [],
        hasRoute: false,

        editableTabsValue: 'index',
        editableTabs: [{
            title: '首页',
            name: 'index',
        }]
    },
    mutations: {

        changeRouteStatus(state, hasRoute) {
            state.hasRoute = hasRoute
            sessionStorage.setItem("hasRoute", hasRoute)
        },

        setMenuList(state, list) {
            state.menuList = list
        },

        setPermList(state, authority) {
            state.permList = authority
        },

        addTabs(state, tab) {
            //    判断是否在栈内
            let index = state.editableTabs.findIndex(item => item.name === tab.name)
            if (index === -1) {
                //    如果没有添加到tabs中
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name,
                })
            }
            //当前激活的tab
            state.editableTabsValue = tab.name
        },
        resetState: (state) => {
            state.menuList = []
            state.editableTabsValue = 'index'
            state.editableTabs = [{
                title: '首页',
                name: 'index',
            }]

        }
    },
    actions: {}
}
